<?php

namespace app\admin\controller;

use app\admin\model\ImageCategory;
use app\admin\model\ImageList;
use app\admin\service\ImageService;
use think\facade\Request;

class Images extends Base
{
    protected $middleware = ['AdminCheck', 'AdminPermission'];

    // 列表
    public function index()
    {
        if (Request::isAjax()) {
            return $this->getJson(ImageList::getList());
        }
        $this->assign('categoryList', ImageCategory::getAll());
        return $this->fetch();
    }
    // 编辑
    public function edit($id)
    {
        if (Request::isAjax()) {
            return $this->getJson(ImageService::goEdit());
        }
        $data = ImageList::where(['image_id' => $id])->find();
        $this->assign('data', $data);
        $this->assign('categoryList', ImageCategory::getAll());
        return $this->fetch();
    }

    public function goStatus()
    {
        return $this->getJson(ImageService::goStatus());
    }

    // 删除
    public function remove($id)
    {
        return $this->getJson(ImageService::goRemove($id));
    }

    // 列表
    public function cate()
    {
        if (Request::isAjax()) {
            return $this->getJson(ImageCategory::getList());
        }
        return $this->fetch();
    }

    // 编辑
    public function editCate($id)
    {
        if (Request::isAjax()) {
            return $this->getJson(ImageService::goEditCate());
        }
        $data = ImageCategory::where(['category_id' => $id])->find();
        $this->assign('data', $data);
        return $this->fetch();
    }

    // 删除
    public function removeCate($id)
    {
        return $this->getJson(ImageService::goRemoveCate($id));
    }
}